package lemna.top.chunyu.batch.step1.repo;

import java.util.Date;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import lemna.top.chunyu.batch.step1.domain.ChunYuPaymentStatement;

public interface ChunYuRepo extends CrudRepository<ChunYuPaymentStatement, Long> {
	ChunYuPaymentStatement findByChanelOrderNo(String chanelorderno);

	ChunYuPaymentStatement findByChunYuOrderNo(String chunyuorderno);

	@Query("SELECT count(DISTINCT  liquidation_Merchant_No) FROM ChunYuPaymentStatement  WHERE (inAccountType=?1 OR inAccountType=?2) and createTime between ?3 and ?4")
	Long countByInAccountTypeAndCreateTimeBetween(int inAccountType1, int inAccountType2, Date startTime, Date endTime);

	@Query("SELECT SUM(orderAmount)-SUM(refundAmount) FROM ChunYuPaymentStatement  WHERE (inAccountType=?1 OR inAccountType=?2) and createTime between ?3 and ?4")
	Long sumByInAccountTypeAndCreateTimeBetween(int inAccountType1, int inAccountType2, Date startTime, Date endTime);

}
